package com.luozhili.Swing;

import javafx.scene.control.ComboBox;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;

/**
 *  下拉框
 *  comboBox
 *
 */
public class Demo11 extends JFrame  {
    JLabel label1;
    JButton jButton;
    JFrame frame=this;
    public Demo11() {
        Container c = this.getContentPane();
        setLayout(new FlowLayout());  //设置网格组布局
        setBounds(300,150,100,100);// xy 在屏幕中出现的位置   wh 窗体大小


        //生成模拟数据
        Integer item[]=new Integer[10];
        for (int i = 0; i < 10; i++) {item[i]=i+1;}


        final JComboBox comboBox = new JComboBox(item);
        c.add(comboBox);

        JButton jButton = new JButton("select");
        jButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.out.println("选中的index   "+comboBox.getSelectedIndex());
                System.out.println("选中的值    "+comboBox.getSelectedItem());
            }
        });
        c.add(jButton);

        this.setVisible(true);
    }




    public static void main(String[] args) {
        new Demo11();

    }
}
